package com.hjm.project.retainRewards.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.retainRewards.domain.RetainRewards;
import com.hjm.project.retainRewards.service.IRetainRewardsService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import javax.annotation.Resource;
import com.hjm.framework.web.page.TableDataInfo;

/**
 * 奖励留存Controller
 * 
 * @author maker-platform
 * @date 2024-04-15
 */
@Controller
@RequestMapping("/retainRewards")
public class RetainRewardsController extends BaseController {
    private String prefix = "retainRewards";

    @Resource
    private IRetainRewardsService retainRewardsService;

    @RequiresPermissions("retainRewards:retainRewards:view")
    @GetMapping()
    public String retainRewards() {
        return prefix + "/retainRewards";
    }

    /**
     * 查询奖励留存列表
     */
    @RequiresPermissions("retainRewards:retainRewards:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RetainRewards retainRewards) {
        startPage();
        List<RetainRewards> list = retainRewardsService.selectRetainRewardsList(retainRewards);
        return getDataTable(list);
    }

    /**
     * 导出奖励留存列表
     */
    @RequiresPermissions("retainRewards:retainRewards:export")
    @Log(title = "奖励留存", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RetainRewards retainRewards) {
        List<RetainRewards> list = retainRewardsService.selectRetainRewardsList(retainRewards);
        ExcelUtil<RetainRewards> util = new ExcelUtil<RetainRewards>(RetainRewards.class);
        return util.exportExcel(list, "retainRewards");
    }

    /**
     * 新增奖励留存
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存奖励留存
     */
    @RequiresPermissions("retainRewards:retainRewards:add")
    @Log(title = "奖励留存", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RetainRewards retainRewards) {
        return toAjax(retainRewardsService.insertRetainRewards(retainRewards));
    }

    /**
     * 修改奖励留存
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
        RetainRewards retainRewards = retainRewardsService.selectRetainRewardsById(id);
        mmap.put("retainRewards", retainRewards);
        return prefix + "/edit";
    }

    /**
     * 修改保存奖励留存
     */
    @RequiresPermissions("retainRewards:retainRewards:edit")
    @Log(title = "奖励留存", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RetainRewards retainRewards) {
        return toAjax(retainRewardsService.updateRetainRewards(retainRewards));
    }

    /**
     * 删除奖励留存
     */
    @RequiresPermissions("retainRewards:retainRewards:remove")
    @Log(title = "奖励留存", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(retainRewardsService.deleteRetainRewardsByIds(ids));
    }
}
